package com.example.ruralservicedigitalplatform.controller.DeliveryMan;

import com.example.ruralservicedigitalplatform.comment.Result;
import com.example.ruralservicedigitalplatform.domain.po.DeliveryMan;
import com.example.ruralservicedigitalplatform.domain.query.PageBean;
import com.example.ruralservicedigitalplatform.service.DeliveryManService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

@Slf4j
@RestController
@Tag(name = "配送员列表")
@RequestMapping("/DeliveryMan")

public class DeliveryManController {

    @Autowired
    private DeliveryManService deliveryManService;

    //根据用户名查询配送员
    @Operation(summary = "根据用户名查询配送员")
    @GetMapping
    public Result accountResult(/*@RequestHeader(name = "token") String token*/){
        //根据用户名查询配送员
        DeliveryMan deliveryMan = deliveryManService.getByName("y");
        return Result.success(deliveryMan);
    }
//分页查询
    @Operation(summary = "配送员分页查询")
    @GetMapping("/all")
    public Result page(@RequestParam(defaultValue = "1") Integer page,
                   @RequestParam(defaultValue = "10")Integer pageSize,
                   Integer deliverymanId,String name, String password,String gender,int phoneNumber,int age, String image, String idNumber,int status, double averageTime, BigDecimal totalDeliveries,BigDecimal rating,
                   @DateTimeFormat(pattern="yyyy-MM-dd") LocalDate begin,
                   @DateTimeFormat(pattern="yyyy-MM-dd")LocalDate end){
    log.info("分页查询,参数:{},{},{},{},{},{},{},{},{},{},{},{},{}",page,pageSize,deliverymanId,name,password,gender,phoneNumber,age,image,idNumber,status,averageTime,totalDeliveries,rating,begin,end);
    //调用service方法进行分页查询
    PageBean pageBean= deliveryManService.page(page,pageSize,deliverymanId,name,password,gender,phoneNumber,age,image,idNumber,status,averageTime,totalDeliveries,rating,begin,end);
    return Result.success(pageBean);
    }

    //更新配送员信息
    @Operation(summary = "更改配送员信息")
    @PutMapping("/update")
    public Result update(@RequestBody DeliveryMan deliveryMan) {
        log.info("更改配送员信息：{}",deliveryMan);
        deliveryManService.update(deliveryMan);
        return Result.success();
    }

    //删除配送员消息
    @Operation(summary = "删除配送员信息")
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids) {
        log.info("删除配送员信息：{}",ids);
        deliveryManService.delete(ids);
        return Result.success();
    }

    //新增配送员信息
    @Operation(summary = "新增配送员信息")
    @PostMapping
    public Result add(@RequestBody DeliveryMan deliveryMan) {
        log.info("新增配送员信息：{}",deliveryMan);
        deliveryManService.add(deliveryMan);
        return Result.success();
    }



}

